package mwa.cs.dao;

import java.math.BigDecimal;
import java.util.Map;

import mwa.cs.database.Database;

/**
 * A class used for managing Dept_Rate
 */
public class DeptRateDAO {
	
    /** a database of this customer */
    private Database db;

    /**
     * Instantiate a new object of this class
     * @param db a database
     */
    public DeptRateDAO(Database db) {
        this.db = db;
    }
    
    /**
     * find dept_amount by site_id, meter_size_code
     * @param pnSiteId
     * @param paMeterSize
     * @return
     */
    public String findDeptAmountByMeterSize(int pnSiteId, String paMeterSize) {
    	String vaSql = "SELECT dept_amount FROM dept_rate WHERE site_id = ? and meter_size_code = ?";
    	Map<String, Object> result = db.querySingle(vaSql, pnSiteId, paMeterSize);
        if (result != null) {
        	String vaDeptAmount = ((BigDecimal) result.get("DEPT_AMOUNT")).toString();
        	if (vaDeptAmount == null) vaDeptAmount = "0";
            return vaDeptAmount;
        } else {
            return "0";
        }
    }

}
